急`求高手帮忙写下C#代码注释 万分感激 明天要答辩...PART1

来源:百度知道 编辑:UC知道 时间:2024/05/09 11:03:45
明天就要答辩了,程序不是我自己做的希望高手给我翻译下代码的含义,
以下代码是请假模块的一个BLL方法代码 希望高手可以逐行解释下 我上台就照你的说!
----------------------------------------------------------------------
//查询员工的剩余假期

public int SelectRemainVacation(int employeeid)
{
string str = "select VacationRemain from tblemployee where employeeid=@employeeid";
Database db = DatabaseFactory.CreateDatabase("OASystemDSN");
DbCommand dbCommand = db.GetSqlStringCommand(str);

db.AddInParameter(dbCommand, "employeeid", DbType.Int32, employeeid);
using (IDataReader dr1 = db.ExecuteReader(dbCommand))
{
while (dr1.Read())
{

aemp.VacationRemain = Convert.ToInt32(dr1["VacationRemain"]);
}
}
return aemp.VacationRemain;

这方法的作用是 通过employedid从 tblemployee表中查出 VacationRemain字段的值。
SQl语句select VacationRemain from tblemployee where employeeid=@employeeid
@employeeid 表示 employeeid是变量

db.AddInParameter(dbCommand, "employeeid", DbType.Int32, employeeid)就是给employeeid赋值,即把传经来的参数值employeeid赋值给SQl语句的employeeid变量。
例如,用的时候 SelectRemainVacation(5);
相当于执行select VacationRemain from tblemployee where employeeid= 5这条Sql语句的结果

public int SelectRemainVacation(int employeeid)
{
//查询TSQL
string str = "select VacationRemain from tblemployee where employeeid=@employeeid";
//数据库基础类!没用过这个!是自定义的还是第三方的?
Database db = DatabaseFactory.CreateDatabase("OASystemDSN");
//建立连接对象
DbCommand dbCommand = db.GetSqlStringCommand(str);
//为TSQL中占位参数@employeeid赋值employeeid 类型为整型
db.AddInParameter(dbCommand, "employeeid", DbType.Int32, employeeid);
//打开连接
using (IDataReader dr1 = db.ExecuteReader(dbCommand))